<template>
  <div class="box">
    <h2>Son1 子组件</h2>
    从vuex中获取的值: <label>{{ $store.state.count }}</label>
    <br>
    <button @click="handleAdd(1)">值 + 1</button>
    <button @click="handleAdd(5)">值 + 5</button>
    <button @click="handleAdd(10)">值 + 10</button>
    <button @click="handleAsyncChange(666)">1s后改成666</button>
    <p>----------------getters使用-开始-----------------</p>
    <div>state中数组: {{ $store.state.list }}</div>
    <div>getters中数组: {{ $store.getters.filterList }}</div>
    <p>----------------getters使用-结束-----------------</p>
    <p>----------------modules数据操作-开始-----------------</p>
    <h4>state:</h4>
    <div>user模块: {{ $store.state.user.userInfo}}</div>
    <div>setting模块: {{ $store.state.setting.theme}} - {{ $store.state.setting.desc }}</div>
    <p>----------------modules使用-结束-----------------</p>
  </div>
</template>

<script>
export default {
  name: 'Son1Com',
  methods: {
    handleAdd (num) {
      this.$store.commit('addCount', {
        num,
        str: '我是测试的'
      })
    },
    handleAsyncChange (num) {
      // console.log(num)
      // 向仓库派发异步任务
      this.$store.dispatch('setAsyncCount', num)
    }
  }
}
</script>

<style lang="css" scoped>
.box{
  border: 3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2 {
  margin-top: 10px;
}
</style>
